import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { DatabaseModule } from './modules/common/database.module';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import { TagsModule } from './modules/tags/tags.module';
import { TextsModule } from './modules/texts/texts.module';
import { GalleryModule } from './modules/gallery/gallery.module';
import { StatsController } from './modules/common/stats.controller';
import { StatsService } from './modules/common/stats.service';
import { WorkflowController } from './modules/common/workflow.controller';
import { WorkflowService } from './modules/common/workflow.service';
import { RequestLoggerMiddleware } from './shared/middleware/request-logger.middleware';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: '.env',
      ignoreEnvFile: false,
    }),
    DatabaseModule,
    AuthModule,
    UserModule,
    TagsModule,
    TextsModule,
    GalleryModule,
  ],
  controllers: [StatsController, WorkflowController],
  providers: [StatsService, WorkflowService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(RequestLoggerMiddleware)
      .forRoutes('*');
  }
}